//
//  ApproveViewController.m
//  F50
//
//  Created by WN on 15/5/15.
//  Copyright (c) 2015年 ZACK. All rights reserved.
//

#import "ApproveViewController.h"

@interface ApproveViewController ()<UIWebViewDelegate>
{
    UIWebView *_webView;
    NSURLRequest *reloadRequest;
}


@end

@implementation ApproveViewController
- (void)createBackground
{
    UIView *nav_bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 64)];
    nav_bg.backgroundColor = RGB(59, 107, 178);
    [self.view addSubview:nav_bg];
    
    
    //中间标题
    UILabel *  nav_title=[[UILabel alloc] initWithFrame:CGRectMake(WIDTH/2 - 80, 20, 160, 40)];
    nav_title.text=@"认证";
    nav_title.textAlignment = NSTextAlignmentCenter;
    nav_title.font=[UIFont boldSystemFontOfSize:20];
    nav_title.textColor=[UIColor whiteColor];
    nav_title.backgroundColor=[UIColor clearColor];
    [nav_bg addSubview:nav_title];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(20, 32, 15, 18);
    [backBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [nav_bg addSubview:backBtn];
    
}

- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = NO;

      NSDictionary * date = [[NSDictionary  alloc]initWithObjectsAndKeys:[USER_DEFAULT objectForKey:@"token"],@"token",nil];
    NSDictionary *pram = [[NSDictionary alloc]initWithObjectsAndKeys:@"member",@"class",@"authinvest",@"func",date,@"param", nil];
    [[AFCustomObject shareAFCustomObject] doRequestActionWithParams:pram success:^(NSDictionary *result) {
        NSLog(@"%@",result);
        NSLog(@"%@",[result objectForKey:@"errMsg"]);
    
        NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:[[result objectForKey:@"result"]objectForKey:@"url"]]];
        reloadRequest = request;
         [_webView loadRequest:request];
    } fail:^{
        NSLog(@"1111111");
    }];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self createBackground];
    
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT - 64)];
    _webView.scalesPageToFit = YES;//自动对页面进行缩放以适应屏幕
    _webView.autoresizesSubviews = NO; //自动调整大小
    _webView.delegate = self;
    [self.view addSubview:_webView];

    
    
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    
    NSString *str = [NSString stringWithFormat:@"%@",request.URL];
    NSLog(@"%@",request.URL);
    NSLog(@"%@",[str isEqualToString:@"http://f50.favtouch.com/index.php?c=attachment&a=album&admin=0"]?@"weqweqwe":@"yes");
    if ([str isEqualToString:@"http://f50.favtouch.com/index.php?c=attachment&a=album&admin=0"]) {
//        UIActionSheet *photoBtnActionSheet =
//        [[UIActionSheet alloc] initWithTitle:nil
//                                    delegate:self
//                           cancelButtonTitle:@"取消"
//                      destructiveButtonTitle:nil
//                           otherButtonTitles:@"从相册选择",@"拍照", nil];
//        [photoBtnActionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque];
//        [photoBtnActionSheet showInView:[self.view window]];
    }
    return YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    NSLog(@"1111111");
    NSLog(@"%@",webView.request.URL);
}

#pragma mark - - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    
    NSLog(@"选择相机还是照片库%ld",(long)buttonIndex);
    if (buttonIndex == 0) {
        //Show Photo Library
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
        {
            UIImagePickerController *imgPickerVC = [[UIImagePickerController alloc] init];
            [imgPickerVC setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
            [imgPickerVC.navigationBar setBarStyle:UIBarStyleBlack];
            imgPickerVC.delegate = self;
//            if (pick_flag)
//            {
//                [imgPickerVC setAllowsEditing:YES];
//            }
            
            //显示Image Picker
            [self presentViewController:imgPickerVC animated:YES completion:^{
                NSLog(@"123435453");
            }];
            
            //                [self presentModalViewController:imgPickerVC animated:YES];
            //                [imgPickerVC release];
        }else {
            NSLog(@"Album is not available.");
        }
    }
    if (buttonIndex == 1) {
        //Take Photo with Camera
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            UIImagePickerController *cameraVC = [[UIImagePickerController alloc] init];
            [cameraVC setSourceType:UIImagePickerControllerSourceTypeCamera];
            [cameraVC.navigationBar setBarStyle:UIBarStyleBlack];
            [cameraVC setDelegate:self];
//            if (pick_flag)
//            {
//                [cameraVC setAllowsEditing:YES];
//            }
            //显示Camera VC
            [self presentViewController:cameraVC animated:YES completion:^{
                NSLog(@"拍照");
            }];
            
            //                [self presentModalViewController:cameraVC animated:YES];
            //                [cameraVC release];
        }
    }
    
}

- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
